package Persistance.KMeans;

import java.util.Vector;

class Cluster
{
	private String			_name;
	private ClusterCenter	_center;
	private double			_sumSqr;
	private Vector<Point>	_points;

	public Cluster(String name)
	{
		this._name = name;
		this._center = null; 
		_points = new Vector<Point>();
	}

	public void setCenter(ClusterCenter c)
	{
		_center = c;
	}

	public ClusterCenter getCenter()
	{
		return _center;
	}

	public void AddPoint(Point dp)
	{ 
		dp.setCluster(this); 
		this._points.addElement(dp);
		calcSumOfSquares();
	}

	public void RemovePoint(Point dp)
	{
		this._points.removeElement(dp);
		calcSumOfSquares();
	}

	public int NumOfPoints()
	{
		return this._points.size();
	}

	public Point getPoint(int pos)
	{
		return this._points.elementAt(pos);
	}

	public void calcSumOfSquares()
	{ 
		int size = this._points.size();
		double temp = 0;
		for (int i = 0; i < size; i++)
		{
			temp = temp	+ ( this._points.elementAt(i)).getCurrentDistance();
		}
		this._sumSqr = temp;
	}

	public double getSumSqr()
	{
		return this._sumSqr;
	}

	public String getName()
	{
		return this._name;
	}

	public Vector<Point> getPoints()
	{
		return this._points;
	}

}